package com.ssy.lingxi.contract.handler.exception;

import com.ssy.lingxi.common.exception.BusinessException;
import com.ssy.lingxi.common.response.Wrapper;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * 全局自定义业务异常处理类
 * @author 万宁
 * @version 2.0.0
 * @date 2020-05-30
 */
@RestControllerAdvice
@Order(1)
public class BusinessExceptionHandler {
    //业务异常不需要记录日志
    //private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(BusinessException.class)
    public Wrapper<?> validationBodyException(HttpServletRequest request, BusinessException exception) {
        //exception.printStackTrace();
        //请求路径 + 错误信息
        //logger.warn(request.getRequestURI().concat(" : ").concat(exception.getNameByCode()));
        return Wrapper.fail(exception.getCode(), exception.getMessage());
    }
}
